package com.cy.dda.web.front.goodsdiligencing;

import com.cy.dda.comm.utils.CommonUtils;
import com.cy.dda.model.Result;
import com.cy.dda.model.ao.goodsdiligencing.ReturnVisitReportSaveAO;
import com.cy.dda.model.vo.goodsdiligencing.ReturnVisitReportDetailVO;
import com.cy.dda.service.goodsdiligencing.ReturnVisitReportService;
import com.cy.dda.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description 前台-家具尽调  回访报告 controller
 * @Author tanyilin
 * @Date 2019/8/28 17:57
 */
@RestController
@RequestMapping("/user/goods/diligencing/returnVisit/report")
@Api(tags = "前台-家具尽调  returnVisit回访报告 controller")
public class ReturnVisitReportController extends BaseController {

    @Autowired
    private ReturnVisitReportService returnVisitReportService;

    @ApiOperation("回访报告详情回显")
    @GetMapping("/get/detail")
    public Result<ReturnVisitReportDetailVO> getDetail(@RequestParam(value = "goodsDiligencingId") Long goodsDiligencingId) {

        ReturnVisitReportDetailVO detailVO = returnVisitReportService.getReturnVisitReportDetail(goodsDiligencingId);
        return ok("获取回访报告数据成功".concat(CommonUtils.isEmpty(detailVO) ? "，但无数据" : ""), detailVO);
    }

    @ApiOperation("提交保存回访报告")
    @PostMapping("/do/save")
    public Result<Map<String, Object>> doSave(@RequestBody @Validated ReturnVisitReportSaveAO saveAO, BindingResult bindingResult) {

        this.checkError(bindingResult);
        Result<Map<String, Object>> result = returnVisitReportService.saveReturnVisitReport(saveAO, this.getUser().getUserId());
        return result;
    }

}
